<?php
class Token extends Zend_Db_Table_Abstract
{
	protected $_name = 'token';
	
	private static $idToken = 0;
	private static $tokenGerado = false;
	
	static function getId(){
		return self::$idToken;
	}
	
	public static function hasToken()
    {
        return self::$tokenGerado;
    }
	
	static function gerarToken(){
		$pass_len = 25; 
		$pass_num = true; 
		$pass_alpha = true;
		$pass_mc = true; 
		$pass_exclude = '';
	    $salt = '';
	    if ($pass_alpha) { // a-z
	        $salt .= 'abcdefghijklmnopqrstuvwxyz';
	        if ($pass_mc) { // A-Z
	            $salt .= strtoupper($salt);
	        }
	    }

	    if ($pass_num) { // 0-9
	        $salt .= '0123456789';
	    }

	    // Remove any excluded chars from salt
	    if ($pass_exclude) {
	        $exclude = array_unique(preg_split('//', $pass_exclude));
	        $salt = str_replace($exclude, '', $salt);
	    }
	    $salt_len = strlen($salt);

	    // Seed the random number generator with today's seed & password's unique settings for extra randomness
	    mt_srand ((int) date('s')*($salt_len+$pass_len));

	    // Generate random password
	    $pass = '';
	    for ($i=0; $i<$pass_len; $i++) {
	        $pass .= substr($salt, mt_rand() % $salt_len, 1);
	    }
	    self::$tokenGerado = true;
		self::$idToken = $pass;		
	}
}
?>